# Maintainer: Antoni Aloy <aaloytorrens@gmail.com>
pkgname=codeblocks
pkgver=20.03
pkgrel=8
pkgdesc="Cross-platform C/C++ and Fortran IDE"
url="https://codeblocks.org"
# riscv64: ftbfs
arch="all !riscv64 !loongarch64"
license="GPL-3.0-or-later"
makedepends="
	autoconf
	automake
	boost-dev
	hunspell-dev
	imagemagick
	libtool
	tinyxml-dev
	wxwidgets-dev
	zip
	"
subpackages="$pkgname-dev $pkgname-doc $pkgname-contrib"
source="https://sourceforge.net/projects/codeblocks/files/Sources/$pkgver/codeblocks-$pkgver.tar.xz
	0001-v20.03-r12008.patch
	0002-v20.03-r12012.patch
	busybox-rm.patch
	gcc11.patch
	make-order.patch
	wxwidgets-3.2.patch
	codeblocks-wxwidgets-3.2-01.patch
	codeblocks-wxwidgets-3.2-02.patch
	codeblocks-wxwidgets-3.2-03.patch
	codeblocks-wxwidgets-3.2-04.patch
	codeblocks-wxwidgets-3.2-05.patch
	codeblocks-wxwidgets-3.2-06.patch
	codeblocks-wxwidgets-3.2-07.patch
	codeblocks-wxwidgets-3.2-08.patch
	codeblocks-wxwidgets-3.2-09.patch
	codeblocks-wxwidgets-3.2-10.patch
	codeblocks-wxwidgets-3.2-11.patch
	codeblocks-wxwidgets-3.2-12.patch
	codeblocks-wxwidgets-3.2-13.patch
	"
options="!check" # No test suite
patch_args="-p1 -F3"

prepare() {
	default_prepare

	convert src/mime/codeblocks.png +set date:create \
		+set date:modify -background none -extent 64x64 src/mime/codeblocks.png

	sed -i 's|$(datadir)/pixmaps|$(datadir)/icons/hicolor/64x64/apps|' \
		src/mime/Makefile.am

	sed -i 's|$(datarootdir)/appdata|$(datarootdir)/metainfo|' \
		Makefile.am src/plugins/contrib/appdata/Makefile.am

	sed -i "s|@VERSION@|$pkgver|" codeblocks.pc.in

	./bootstrap
}

build() {
	export CFLAGS="$CFLAGS -O2 -flto=auto"
	export CXXFLAGS="$CXXFLAGS -O2 -flto=auto"

	# Deactivate wxsmith-related plugins because they depend on wxpropgrid
	./configure \
		--prefix=/usr \
		--build=$CBUILD \
		--host=$CHOST \
		--with-boost-libdir=/usr/lib \
		--with-contrib-plugins=all,-FileManager

	sed -i 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
	make
}

package() {
	make DESTDIR="$pkgdir" install

	# Replace pkgconfig file for 20.03 version (Reason: 20.03svn version is invalid)
	find "$pkgdir" -type f -exec sed -i 's/20.03svn/20.03/g' {} +
}

dev() {
	default_dev
	pkgdesc="$pkgdesc (SDK)"
}

contrib() {
	pkgdesc="$pkgdesc (contrib plugins)"

	# Move plugins and wxContribItems to this subpackage
	amove usr/lib/codeblocks

	# Move contrib metainfo file
	amove usr/share/metainfo/codeblocks-contrib.metainfo.xml

	# Move optional plugins to this subcategory
	amove \
		usr/share/codeblocks/AutoVersioning.zip \
		usr/share/codeblocks/BrowseTracker.zip \
		usr/share/codeblocks/Cccc.zip \
		usr/share/codeblocks/CppCheck.zip \
		usr/share/codeblocks/Cscope.zip \
		usr/share/codeblocks/DoxyBlocks.zip \
		usr/share/codeblocks/EditorConfig.zip \
		usr/share/codeblocks/EditorTweaks.zip \
		usr/share/codeblocks/HexEditor.zip \
		usr/share/codeblocks/IncrementalSearch.zip \
		usr/share/codeblocks/MouseSap.zip \
		usr/share/codeblocks/NassiShneiderman.zip \
		usr/share/codeblocks/Profiler.zip \
		usr/share/codeblocks/ProjectOptionsManipulator.zip \
		usr/share/codeblocks/RegExTestbed.zip \
		usr/share/codeblocks/ReopenEditor.zip \
		usr/share/codeblocks/SmartIndentCpp.zip \
		usr/share/codeblocks/SmartIndentFortran.zip \
		usr/share/codeblocks/SmartIndentHDL.zip \
		usr/share/codeblocks/SmartIndentLua.zip \
		usr/share/codeblocks/SmartIndentPascal.zip \
		usr/share/codeblocks/SmartIndentPython.zip \
		usr/share/codeblocks/SmartIndentXML.zip \
		usr/share/codeblocks/SpellChecker \
		usr/share/codeblocks/SpellChecker.zip \
		usr/share/codeblocks/SymTab.zip \
		usr/share/codeblocks/ThreadSearch.zip \
		usr/share/codeblocks/ToolsPlus.zip \
		usr/share/codeblocks/Valgrind.zip \
		usr/share/codeblocks/abbreviations.zip \
		usr/share/codeblocks/byogames.zip \
		usr/share/codeblocks/cb_koders.zip \
		usr/share/codeblocks/codesnippets.zip \
		usr/share/codeblocks/codestat.zip \
		usr/share/codeblocks/copystrings.zip \
		usr/share/codeblocks/dragscroll.zip \
		usr/share/codeblocks/envvars.zip \
		usr/share/codeblocks/exporter.zip \
		usr/share/codeblocks/headerfixup.zip \
		usr/share/codeblocks/help_plugin.zip \
		usr/share/codeblocks/images/codesnippets \
		usr/share/codeblocks/keybinder.zip \
		usr/share/codeblocks/lib_finder \
		usr/share/codeblocks/lib_finder.zip \
		usr/share/codeblocks/occurrenceshighlighting.zip \
		usr/share/codeblocks/rndgen.zip

	mkdir -p "$subpkgdir"/usr/share/codeblocks/images
}

sha512sums="
f97c1a02d31f0be4dc08b1f19b57bd0d3cba375ab5f33ab91b2a2df7817018f5b3e3063ed07199a3970644f1caa7c7e511db2034c73264f5f4963046d65b0097  codeblocks-20.03.tar.xz
98584a93790974481a669cb86a01efe42690fe4a4e0a6c04abc15e3ea0c037be0b0cdc63164907e0c9f51414bb32b2879f6a06117d1374a4288a0a03bec4080f  0001-v20.03-r12008.patch
1580f63e559470f58990831c49c8885ba980416326bc66a5564a47681d9f33124809824d7e6caab2ebfbde8bf57def4e9e06a41d30379bb7aa5a2deaee3803c1  0002-v20.03-r12012.patch
bc78d166c14ef093eed600b14a5861cdb9f566151129e85f8bbf89a9e018823458628bb2152eef0f90f1543cdcc9f22718428c3abac8e44a88f4d797de34715c  busybox-rm.patch
af99cd88ae857abc29a7d487d5b2b298550f825787b3d883d49e083ddc5c3747e179bb882322162355c82b3b2e34c138531eb62b5647814ce8ad0a59ce524931  gcc11.patch
651e8aa03876e6512d3c981094f41f990e9110a0157f8d9393bc62e5b8c0250ef26d1873ebaa4b8facc02da0436ae2809d951a821a3a80670c5ccd3496dc8283  make-order.patch
1515434b817ce6b222b6204a9f10a0569eca588d87db9b93427241b946991bfb40fb9855e431c2e15b5f0f19f04f07be85f96b40b498195293a25093d980e55d  wxwidgets-3.2.patch
bf78ee152c9fcff2a564c1af6a1b67f2aaeb596f4ca987551d2f65aec918678f0bc1d7b286d5e6f919378a635aae4f46fbc0ec55db9f1048396e99725329a69b  codeblocks-wxwidgets-3.2-01.patch
6060b267d41392f03642fc24b9680a72ba9ea70fb8731344adbf8d97fd89e243426f405ba4331c00c7c73450977e29001a6a80ea0b7bea17087027e646645a02  codeblocks-wxwidgets-3.2-02.patch
79665bf69515e085dcdeab2a8c78c1f88eafe3cebc117f25bec7d29d17ebb175d817a731fa8f74c37ab6b85c8e6111f510255ba60dc345fe57055d8e6f5db200  codeblocks-wxwidgets-3.2-03.patch
c82a411e9d10a6042935911e9f184ff954d958921a95568f27e7636461dcf370bb8aefd4f23db198eaba48fb12a43f098d9cd8a61b5cf500a34f5b1110a5c4f5  codeblocks-wxwidgets-3.2-04.patch
34c0de6e4e208df5f7675dd4dc2283c6135d8bb9ef296ef166af6a4e184bce6bc96c039d9e2c9a6bd974f6804fe49daa09d2bfeff1a6622a5803bba718bce84a  codeblocks-wxwidgets-3.2-05.patch
a2cf64f07f39b6fbc3280925b8dcc7cb13017916c28f6be0bed437cb1f71449450119400059b28b8efaf9a70591b5218bc6673b7d598fd03c31d18c1eb964f39  codeblocks-wxwidgets-3.2-06.patch
534096f9bcbb9a19732709cb54e479c73e2bbd2e70b61892c296a6d6f1b33c8e09114117824118ab96a83e075ffa203ca60fc3db47ef9a32615bb001f83017ed  codeblocks-wxwidgets-3.2-07.patch
290cb5ce55ff618fd3d54328c3b04bd1e64cb58851bae6d89a15adcbd097cdb1dd9efc1fdd25fc848bc42f0b75dfea6da8281247f9eac948e6787de3f2821d41  codeblocks-wxwidgets-3.2-08.patch
4032512a4b08e8efd1d21912257dff5768847433b511904c3aaf705e870564c9e9880366da4858de5afdc2eae75819c7a0a9a5bed75670f6e00577aba02e473b  codeblocks-wxwidgets-3.2-09.patch
75996bec0d7f88df33e983c14db92ca6c6e97e04c2eb4c448350d8e67d0e5db864c85fd040c40073d7e779b4b39e097da1a9e7aacabc28c4afa8c2a380e69863  codeblocks-wxwidgets-3.2-10.patch
f195403d52ba53de3e55bdfb54461414bdb40c62ea9079446600377ec0cf7e739b74c9aadba23fd3a68f0e1270277a138901531b59630063c76a1fe608f1e278  codeblocks-wxwidgets-3.2-11.patch
6943970fc405bfbe1c656f117ae22fced8f80eb149befe2a1b8c3a9e906f6d1dbae1d89a80c5f2823ba60ab3c97b71a9f2d5a275e9070ddef2672ff6ed7cd821  codeblocks-wxwidgets-3.2-12.patch
cc124bfad81ad1c00d6bc50b6a0a7a8daedfce75de6f321021434bde4569496068dfd6600f0ffc0c6957f739ad149f3656eef300402762f7234f2714b82a17e3  codeblocks-wxwidgets-3.2-13.patch
"
